package au.com.handsunited.aop.notifications;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.model.BaseEntity;
import au.com.handsunited.model.message.Message;
import au.com.handsunited.service.EmailService;

/**
 *
 * @author Arun Chandrasekhar
 */
@Aspect
public class EntityNotificationsAdvice {


	private final EmailService emailService;

	private static Logger logger = LoggerFactory.getLogger(EntityNotificationsAdvice.class);


	/**
	 * @param emailService
	 */
	public EntityNotificationsAdvice(EmailService emailService) {
		super();
		this.emailService = emailService;
	}


	/**
	 *
	 */
	public void postMessage(BaseEntity recipient, Message message) {
	    Map<String, Object> model = new HashMap<String, Object>();
	    model.put("recipient", recipient);
	    model.put("message", message.getText());
	    model.put("poster", message.getPoster());
		emailService.sendEmail(
				recipient.getContactInfo().getEmailAddress(),
				"velocity/emails/entity/newMessage.vm",
				message.getPoster().getName() + " just sent you a message!",
				model);
	}


}
